﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="RoleMemberList.aspx.cs" Inherits="Facefar.Futures.Manage.Right.RoleMemberList" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="tb" style="padding: 5px; height: auto;">
        <div style="margin-bottom: 5px">
            <%=R(LanguageModule.M_Common, "MemberAccount","会员账号") %>：<input id="MemberAccount" name='MemberAccount' class="input_no_width" />
            <%=R(LanguageModule.MemberBasicInfo, "PlacementAccount","父級會員賬號") %>：<input id="ParentMemberAccount" name='ParentMemberAccount' class="input_no_width" />
            <a href="#" class="easyui-linkbutton " data-options="iconCls:'icon-search'" onclick="query()"><%=R(LanguageModule.M_Common, "Query","查询") %></a>
        </div>
        <div style="margin-bottom: 5px">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="add()"><%: R(LanguageModule.M_Common, "Add", "新增") %></a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-undo'" onclick="del()"><%: R(LanguageModule.M_Common, "Delete", "删除") %></a>
        </div>
    </div>
    <table id="table" class="easyui-datagrid" border="0px"
        data-options="url:'Handlers/Right_MemberRoleHandler.ashx?type=GetRoleMemberList&RoleID=<%: Request.QueryString["RoleID"] %>',
            rownumbers:true,
            pageSize:50,
            singleSelect:false,
            pagination:true,
            fit:true,
            fitColumns:true,
            toolbar:'#tb'">
        <thead>
            <tr>
                <th data-options="field:'MemberAccount'"><%: R(LanguageModule.M_Common, "MemberAccount", "會員賬號") %></th>
                <th data-options="field:'MemberID'"><%: R(LanguageModule.MemberBasicInfo, "MemberID", "會員ID") %></th>
                <th data-options="field:'Name'"><%=R(LanguageModule.MemberBasicInfo, "MemberName") %></th>
                <th data-options="field:'ParentMemberAccount'"><%=R(LanguageModule.MemberBasicInfo, "PlacementAccount","父級會員賬號") %></th>
            </tr>
        </thead>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
        <script type="text/javascript">
            var roleID = "<%: Request.QueryString["RoleID"] == null ? "0" : Request.QueryString["RoleID"] %>";
            var flag = false;

            function query() {
                $('#table').datagrid('load', {
                    MemberAccount: $('#MemberAccount').val(), 
                    ParentMemberAccount: $('#ParentMemberAccount').val()
                });
            }

            function add() {
                var diag = new top.Dialog();
                diag.Width = 1000;
                diag.Height = 600;
                diag.Title = "<%: R(LanguageModule.M_Common, "Add") %>";
                diag.URL = "Right/MemberInfoList.aspx";
                diag.OKEvent = function () {
                var row = diag.innerFrame.contentWindow.select();
                if (row) {
                    for (var i = 0; i < row.length; i++) {
                        $.post("Handlers/Right_MemberRoleHandler.ashx?type=addRoleMember", { MemberAccount: row[i].MemberAccount, RoleID: roleID }, function (data) {
                            if (data.isSuccess) {
                                $('#table').datagrid('reload');
                            }
                            else {
                                top.Dialog.alert(data.message);
                            }
                        }, "json");
                    }
                }
                else {
                    top.Dialog.alert("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
                }
                diag.close();
            };
            diag.show();
        }

        function del() {
            var rows = $('#table').datagrid('getSelections');
            if (rows) {
                top.Dialog.confirm("<%: R(LanguageModule.M_Common, "confirm_Delete", "您確定要刪除嗎？") %>", function () {
                    $.map(rows, function(row){
                        $.post("Handlers/Right_MemberRoleHandler.ashx?type=deleteRoleMember", { MemberAccount: row.MemberAccount, RoleID: roleID }, function (data) {
                            if (data.isSuccess) {
                                $('#table').datagrid('reload');
                            }
                            else {
                                top.Dialog.alert(data.message);
                            }
                        }, "json");
                    });
                }, null);
            }
            else {
                top.Dialog.alert("<%: R(LanguageModule.M_Common, "SelectRecord") %>");
            }
        }

        $(function(){
            if(roleID == "0"){
                diag.close();
                top.Dialog.alert("<%: R(LanguageModule.Right_Roleinfo, "RoleIDError", "請選擇角色再添加用戶。") %>");
            }
        });
    </script>
</asp:Content>
